home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / viewwrld / viewwrld.lha / viewworld / gr / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-21  |  5.6 KB  |  199 lines

  1. /* $Id: help.c,v 2.3 89/09/20 17:01:37 mbp Exp $
  2.  *
  3.  * help.c: procedures for reading and displaying help file in a window
  4.  */
  5.  
  6. /************************************************************************
  7.  *        Copyright (C) 1989 by Mark B. Phillips                  *
  8.  *                                     *
  9.  * Permission to use, copy, modify, and distribute this software and    *
  10.  * its documentation for any purpose and without fee is hereby granted, *
  11.  * provided that the above copyright notice appear in all copies and    *
  12.  * that both that copyright notice and this permission notice appear in *
  13.  * supporting documentation, and that the name of Mark B. Phillips or   *
  14.  * the University of Maryland not be used in advertising or publicity   *
  15.  * pertaining to distribution of the software without specific, written *
  16.  * prior permission.  This software is provided "as is" without express *
  17.  * or implied warranty.                                                 *
  18.  ************************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include "gr.h"
  22. #include "internal.h"
  23.  
  24. /* Help subframe has one panel and one text subwindow for displaying
  25.  * help page */
  26. Frame    GR_help_frame = NULL;
  27. Panel    GR_help_panel = NULL;
  28. Textsw    GR_help_textsw = NULL;
  29.  
  30. /* Gadgets for help panel: */
  31. static Panel_item help_done_button;
  32.  
  33. /* Notification procedure for button in help panel: */
  34. static int help_done_button_proc();
  35.  
  36. /* Name of file to display in help window */
  37. #define HELP_FILE_NAME_LENGTH 256
  38. static char help_file[HELP_FILE_NAME_LENGTH+1];
  39. static int help_file_specified=0;
  40.  
  41. /*-----------------------------------------------------------------------
  42.  * Function:    GR_display_help_window
  43.  * Description: display the help window
  44.  * Args:    (none)
  45.  * Returns:     0 for success, 1 for failure
  46.  * Notes:       The file is read and the window created on the first
  47.  *        call.  After that, we just redisplay the
  48.  *        already-created window.
  49.  */
  50. GR_display_help_window()
  51. {
  52.   char msg[GR_ERROR_MESSAGE_LENGTH+1];
  53.  
  54.   /* If the help frame hasn't been created yet, create it */
  55.   if (GR_help_frame==NULL) {
  56.  
  57.     if (!help_file_specified)
  58.       construct_help_file_name(help_file);
  59.  
  60.     if (!GR_file_openable(help_file, "r")) {
  61.       sprintf(msg,"I can't find help file \"%s\" !", help_file);
  62.       GR_error(msg);
  63.       return(1);
  64.     }
  65.  
  66.     GR_help_frame =
  67.       window_create(GR_base_frame, FRAME,
  68.             WIN_FONT, GR_regular_font,
  69.             FRAME_LABEL, "Help Window",
  70.             FRAME_SHOW_LABEL, TRUE,
  71.             WIN_X, 206,
  72.             WIN_Y, 169,
  73.             0);
  74.     if (GR_help_frame == NULL) {
  75.       GR_error("Cannot open any more windows !");
  76.       return(1);
  77.       }
  78.  
  79.     GR_help_panel =
  80.       window_create(GR_help_frame, PANEL,
  81.             WIN_X, 0,
  82.             WIN_Y, 3,
  83.             WIN_HEIGHT,    ATTR_ROW(1)+4,
  84.             WIN_FONT, GR_regular_font,
  85.             0);
  86.     if (GR_help_panel == NULL) {
  87.       GR_error("Cannot open any more windows !");
  88.       window_destroy(GR_help_frame);
  89.       GR_help_frame = NULL;
  90.       return(1);
  91.       }
  92.  
  93.     help_done_button = 
  94.       panel_create_item(GR_help_panel, PANEL_BUTTON, 
  95.             PANEL_ITEM_X, ATTR_COL(0),
  96.             PANEL_ITEM_Y, ATTR_ROW(0),
  97.             PANEL_LABEL_IMAGE,
  98.               panel_button_image(GR_help_panel, "Done", 3, 0),
  99.             PANEL_NOTIFY_PROC, help_done_button_proc,
  100.             0);
  101.  
  102.     GR_help_textsw =
  103.       window_create(GR_help_frame, TEXTSW,
  104.             WIN_ERROR_MSG, "I can'tfind the help file !",
  105.             WIN_FONT,            pf_default(),
  106.             WIN_X,                  0,
  107.             WIN_Y,            ATTR_ROW(2)+5,
  108.             WIN_HEIGHT,             ATTR_ROW(30),
  109.             WIN_WIDTH,              ATTR_COL(78),
  110.             TEXTSW_IGNORE_LIMIT,    TEXTSW_INFINITY,
  111.             TEXTSW_AUTO_INDENT,     TRUE,
  112.             TEXTSW_BROWSING,        TRUE,
  113.             TEXTSW_DISABLE_LOAD,    TRUE,
  114.             TEXTSW_DISABLE_CD,      TRUE,
  115.             TEXTSW_FILE,        help_file,
  116.             0);
  117.     if (GR_help_textsw == NULL) {
  118.       GR_error("I can't create the help page");
  119.       window_destroy(GR_help_frame);
  120.       GR_help_frame = NULL;
  121.       return(1);
  122.       }
  123.  
  124.     window_fit(GR_help_frame);
  125.     GR_register_interposer(GR_help_frame);
  126.  
  127.   }  /* end of "if (GR_help_frame==NULL) ..." */
  128.  
  129.   /* Now display the help frame */
  130.   if (GR_help_frame!=NULL) {
  131.     window_set(GR_help_frame, WIN_SHOW, TRUE, 0);
  132.     return(0);
  133.   }
  134.   else
  135.     return(1);
  136. }
  137.  
  138. /*-----------------------------------------------------------------------
  139.  * Function:    GR_set_help_file
  140.  * Description:    specify the name of the file to display in the help window
  141.  * Args  IN:    filename: the file's name
  142.  * Notes:    This does not change the visibility status of the
  143.  *        help window
  144.  */
  145. GR_set_help_file(filename)
  146. char *filename;
  147. {
  148.   char msg[GR_ERROR_MESSAGE_LENGTH+1];
  149.  
  150.   if (filename == NULL) return(1);
  151.  
  152.   if (strlen(filename) > HELP_FILE_NAME_LENGTH) {
  153.     GR_error("Your help file name is tooooo looooooooooonnnnnnnnnggggg !!");
  154.     return(1);
  155.   }
  156.  
  157.   strcpy(help_file, filename);
  158.   help_file_specified = 1;
  159.  
  160.   /* If the help window has been created, load the new file */
  161.   if (GR_help_textsw != NULL) {
  162.     if (!GR_file_openable(help_file, "r")) {
  163.       sprintf(msg,"I can't find help file \"%s\" !", help_file);
  164.       GR_error(msg);
  165.       return(1);
  166.     }
  167.     else
  168.       window_set(GR_help_textsw, TEXTSW_FILE, help_file, 0);
  169.   }
  170.  
  171.   return(0);
  172. }
  173.  
  174. static int
  175. help_done_button_proc()
  176. {
  177.   window_set(GR_help_frame, WIN_SHOW, FALSE, 0);
  178. }
  179.  
  180. static
  181.   construct_help_file_name(fname)
  182. char *fname;
  183. {
  184.   extern char *getenv();
  185.   char *gr_lib;
  186.  
  187.   /* First look in GR_LIB */
  188.   gr_lib = getenv("GR_LIB");
  189.   if (gr_lib != NULL) {
  190.     sprintf(fname,"%s%s%s",
  191.         gr_lib, (gr_lib[strlen(gr_lib)-1]=='/') ? "" : "/",
  192.         "gr.help");
  193.     if (GR_file_openable(fname, "r")) return;
  194.   }
  195.  
  196.   /* If not there, then use default */
  197.   strcpy(fname, DEFAULT_HELP_FILE);
  198. }
  199.